Online-Academy
Look, Read, Understand, Apply

Operating System

FAQs - II

  1. What are the Basic Requirements of Primary Memory?

    Primary memory should provide:

    • Storage for currently executing programs and data.
    • Fast access by the CPU
    • Addressability, so each memory location can be uniquely accessed.
    • Protection so one process cannot improperly access another process's memory.
    • Efficient allocation and management of memory.

  2. Explain Paging Scheme with Diagram

    Paging divides logical memory into fixed-size pages and physical memory into equal-size frames. A page table maps each logical page to a physical frame.
    Conceptually:

    Logical Address
    PageOffset
    |
    Page Table
    Page 0 ---->Frame 5
    Page 1 ---->Frame 2
    Page 2 ---->Frame 7
    Page 3 ---->Frame 1
    |
    Physical Memory
    Frame 0
    Frame 1Page 3
    Frame 2Page 1
    Frame 3
    Frame 4
    Frame 5Page 0
    Frame 6
    Frame 7Page 2

    The logical address consists of:
    Page number + Offset
    The page number is used to index the page table, which gives the corresponding frame number. The frame number and offset form the physical address. Advantages

    • Eliminates external fragmentation
    • Allows non-contiguous memory allocation
    • Makes virtual memory possible
    Disadvantages:
    • Pages-table storage overhead
    • May cause internal fragmentation

  3. What is a Page Fault? Answer : A page fault occurs when a process attempts to access a page that is not currently present in physical memory. The OS then:
    • Detects the page fault.
    • Locates the required page on secondary storage.
    • Finds a free frame or selects a victim page.
    • Loads the required page into memory.
    • Updates the page table.
    • Restarts the interrupted instruction.
  4. Differentiate between Paging and Segmentation. Memory divided into variable-size segments
    PagingSegmenation
    Memory divided into fixed-size pages
    Physical memory divided into framesPhysical memory does not required fixed-size units.
    Programmer usually does not see pagesSegments represent logical program units
    Can cause internal fragmentationCan cause external fragmentation
    Address = page number + offsetAddress = segment number + offset
    Mainly supports physical memory managementRepresents logical divisions such as code, date, stack
  5. Explain List File System Allocation Methods.

    Answer: The major file allocation methods are:

    • Contiguous allocation
    • Linked allocation
    • Indexed allocation
    Modern file systems may use more sophisticated variations of these approaches

  6. Differentiate between Sequential vs Random File Access.
    Sequential AccessRandom Access
    Data is accessed in orderData can be accessed directly
    To reach a later record, earlier records may need to be processed A particular location can be accessed directly.
    Suitable for tapes and sequential processingSuitable for disks and databases
    Generally simplerRequires direct positioning / indexing
  7. What is a Directory?

    A directory is a file-system structure that stores information about files and possibly other directories. It can contain:

    • File names
    • File locations
    • File types
    • Metadata
    • References to file-control information

  8. Explain Hierarchical Directory Structure Answer: A hierarchical directory structure organizes files and directories in a tree-like structure. The root directory is at the top. Subdirectories can contain files and additional subdirectories. Advantages:
    • Easy organization
    • Supports grouping of related files
    • Allows unique paths
    • Provides convenient file management
  1. Explain Implementation of FAT File System

    Answer: FAT (File Allocation Table) is a file-system structure in which a table records the allocation and linkage of disk clusters. A simplified FAT structure is:

    Boot / Reserved Area
    File Allocation Table
    Root Directory
    Data Area
    Clsuter 2
    Clsuter 3
    Clsuter 4
    Clsuter 5
    The FAT contains entries corresponding to data clusters. For example:
    ClusterFAT Entry
    25
    58
    8EOF
    This means the file occupies: Cluster 2 --> Cluster 5 --> Cluster 8 --> End of File. The directory stores information such as the file name and starting cluster. The FAT is then followed to locate the remaining clusters belonging to the file.
  2. How is Free Space Managed on Disk?

    The OS must maintain information about which disk blocks are free and which are allocated. Common techniques include:

    • Bit Vector: One bit represents each disk block.
                Block:  0 1 2 3 4 5 6 7
                Bit:      1 0 0 1 1 0 0 1
                For example, if 0 = free and 1 = allocated, blocks 1, 2, 5, and 6 are free.
              
    • Linked List: All free blocks are linked together

      Free Block --> Block 4 --> Block 8 --> Block 15 --> Block 21

  3. Grouping: The addresses of several free blocks are stored in one free block, along with the address of another group.
  4. Counting: Instead of recording every free block individually, the system records:
    • Starting Block
    • Number of consecutive free blocks
    • Example:
    • Start = 100, Count = 20. This means block 100 - 119 are free.
  5. What is Deadlock?

    Answer : A deadlock is a situation in which a group of processes is permanently blocked because each process is waiting for a resource held by another process in the group. Example:

  6. P1 holds R1 --> waiting for R2
  7. P2 holds R2 --> waiting for R1
  8. Neither process can process. The four necessary conditions for deadlock are:

    1. Mutual Exclusion
    2. Hold and wait
    3. No preemption
    4. Circular wait

  9. Explain Banker's Algorithm.

    Answer: The Banker's algorithm is a deadlock-avoidance algorithm. It checks whether granting a resource request will leave the system in a safe state. It requires information about:

    • Available resources
    • Maximum resource requirements
    • Resources currenlty allocated
    • Remaining resource needs
    Basic procedure:
    1. Calculate: Need = Maximum - Allocation
    2. Find a process whose remaining Need is less than or equal to Available.
    3. Assume that process completes.
    4. Release its allocated resources.
    5. Add those resources to Available.
    6. Repeat for other processes.
    7. If all processes can finish, the state is safe.
    8. If no suitable process can be found while processes remain, the state is unsafe.
          if Resource Available: 
            check if P1 can finish?
              if yes 
                release resources
                  check if P2 can finish?
              else try P2
        
    The algorithm grants a request only if the resulting state remains safe.

  10. Explain Deadlock Detection, Prevention, Avoidance, and Recovery.

    Answer: Prevention ensures that at least one of the four necessary deadlock conditions cannot occur. For example:

    • Eliminate mutual exclusion where possible.
    • Prevent hold and wait.
    • Allow resource preemption.
    • Impose an ordering on resource acquisition to prevent circular wait.

    Deadlock Avoidance: The OS examines resource requests before granting them. It ensures that the system remains in a safe state. Example: Banker's algorithm.

    Deadlock Detection: The OS allows deadlocks to occur and periodically checks whether one has occurred. Methods include:

    • Wait-for-graphp
    • Resource-allocation graph
    • Detection algorithms based on available and allocated resources

    Deadlock: After detecting deadlock, the OS can recover by:

    • Terminating one or more processes.
    • Preempting resources.
    • Rolling back processes to a safe state.